<script>
import axios from "axios";
import { ref } from "vue";

export default {
  setup() {
    const log = ref([]);

    const mylog = () => {
      axios.get("/log/result")
          .then(result => {
            let data = result.data.data;
            let a = [];
            for (let dataKey in data) {
              a.push(JSON.parse(data[dataKey]));
            }
            log.value = a;
          })
          .catch(error => {
            console.error(error);
          });
    };

    mylog();

    const formatTime = (row) => {
      const date = new Date(row.createTime);
      const year = date.getFullYear();
      const month = date.getMonth() + 1;
      const day = date.getDate();
      const hour = date.getHours();
      const minute = date.getMinutes();
      const second = date.getSeconds();

      return `${year}年${month}月${day}日 ${hour}:${minute}分:${second}秒`;
    };

    return {
      formatTime,
      log
    };
  },
};
</script>

<template>
  <el-table :data="log" stripe style="width: 100%" table-layout="fixed">
    <el-table-column prop="username" label="用户" />
    <el-table-column prop="method" label="操作方式" />
    <el-table-column prop="createTime" label="操作时间" :formatter="formatTime" />
    <el-table-column prop="ipaddr" label="Ip地址" />
  </el-table>
</template>

<style scoped>
</style>